﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace WebSite.Core
{
    /// <summary>
    /// 设置横向菜单当前选中项
    /// </summary>
    public class NavHelper
    {
        public static void SetNavMenuSelectedIndex( int index )
        {
            var currentpage = HttpContext.Current.Handler as Page;
            var master = currentpage.Master;

            while (master != null && !(master is MasterBasePage) && master.Master != null)
            {
                master = master.Master;
            }

            if (master == null)
            {
                // throw new Exception("No MasterBasePage");
                return;
            }

            var m = master as MasterBasePage;
            m.NavMenu1.SelectedIndex = index;
        }

        public static void SetNavStepCurrentStep( int step )
        {
            var currentpage = HttpContext.Current.Handler as Page;
            var master = currentpage.Master;

            while (master != null && !(master is MasterBasePageNevStep) && master.Master != null)
            {
                master = master.Master;
            }

            if (master == null)
            {
                // throw new Exception("No MasterBasePage");
                return;
            }

            var m = master as MasterBasePageNevStep;
            // m.NavMenu1.SelectedIndex = index;

            string dummy = "";
            switch (step)
            {
                case 0:
                    dummy = "step0";
                    break;
                case 1:
                    dummy = "step1";
                    break;
                case 2:
                    dummy = "step2";
                    break;
                case 3:
                    dummy = "step3";
                    break;
                case 4:
                    dummy = "step3_half";
                    break;
                case 5:
                    dummy = "step4";
                    break;
                case 6:
                    dummy = "step5";
                    break;
            }
            m.NavStep1.StepClassName = dummy;
        }
    }
}